package cn.sky.demo.listener;

import cn.sky.demo.domain.vo.UserVO;
import org.springframework.context.ApplicationListener;
import org.springframework.session.Session;
import org.springframework.session.events.SessionDeletedEvent;
import org.springframework.stereotype.Component;

/**
 * @author sky
 * @date 2025年09月25日 9:12
 * @description Session监听器
 * @since 1.0.0
 */
@Component
public class SessionEventListener implements ApplicationListener<SessionDeletedEvent >{
    private static final String CURRENT_USER = "currentUser";
    /**
     * 监听Session删除事件
     *
     * @param event
     */
    @Override
    public void onApplicationEvent(SessionDeletedEvent event) {
        Session session = event.getSession();
        UserVO userVo = (UserVO) session.getAttribute(CURRENT_USER);
        System.out.println("session is deleted,  sessionId is:" + session.getId() + " and invalid session's user is:" + userVo);
    }
}
